/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialogPreview.java
 *
 * Created on 16/02/2011, 19:30:53
 */

package systole.view.preview;

import java.awt.event.KeyEvent;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.jdesktop.application.Action;
import systole.utils.ImageUtils;


/**
 *
 * @author jmj
 */
public class JDialogPreview extends javax.swing.JDialog {

    private PreviewController controller;

    /** Creates new form JDialogPreview */
    public JDialogPreview(java.awt.Frame parent, PreviewController controller) {
        super(parent, true);
        initComponents();
        this.controller = controller;
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
        this.getRootPane().registerKeyboardAction(new PreviewCloseListener(controller), stroke, JComponent.WHEN_FOCUSED);
        this.setIconImage(ImageUtils.buildImage("resources/icons/preview/previewsignal16.png"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlCenter = new javax.swing.JPanel();
        jPnlTop = new javax.swing.JPanel();
        jTxtFile = new javax.swing.JTextField();
        jLblFile = new javax.swing.JLabel();
        jBtnFile = new javax.swing.JButton();
        jChkInverted = new javax.swing.JCheckBox();
        jPnlBottom = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPnlClose = new javax.swing.JButton();
        jPnlRigth = new javax.swing.JPanel();
        jPnlLeft = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getResourceMap(JDialogPreview.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setIconImage(null);
        setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        setName("Form"); // NOI18N

        jPnlCenter.setName("jPnlCenter"); // NOI18N
        jPnlCenter.setLayout(new java.awt.BorderLayout());
        getContentPane().add(jPnlCenter, java.awt.BorderLayout.CENTER);

        jPnlTop.setName("jPnlTop"); // NOI18N
        jPnlTop.setPreferredSize(new java.awt.Dimension(650, 60));

        jTxtFile.setEditable(false);
        jTxtFile.setText(resourceMap.getString("jTxtFile.text")); // NOI18N
        jTxtFile.setToolTipText(resourceMap.getString("jTxtFile.toolTipText")); // NOI18N
        jTxtFile.setName("jTxtFile"); // NOI18N

        jLblFile.setFont(jLblFile.getFont().deriveFont(jLblFile.getFont().getStyle() | java.awt.Font.BOLD));
        jLblFile.setText(resourceMap.getString("jLblFile.text")); // NOI18N
        jLblFile.setName("jLblFile"); // NOI18N

        jBtnFile.setText(resourceMap.getString("jBtnFile.text")); // NOI18N
        jBtnFile.setToolTipText(resourceMap.getString("jBtnFile.toolTipText")); // NOI18N
        jBtnFile.setName("jBtnFile"); // NOI18N
        jBtnFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnFileActionPerformed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getActionMap(JDialogPreview.class, this);
        jChkInverted.setAction(actionMap.get("checkBoxInvertedChange")); // NOI18N
        jChkInverted.setText(resourceMap.getString("jChkInverted.text")); // NOI18N
        jChkInverted.setToolTipText(resourceMap.getString("jChkInverted.toolTipText")); // NOI18N
        jChkInverted.setName("jChkInverted"); // NOI18N

        javax.swing.GroupLayout jPnlTopLayout = new javax.swing.GroupLayout(jPnlTop);
        jPnlTop.setLayout(jPnlTopLayout);
        jPnlTopLayout.setHorizontalGroup(
            jPnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlTopLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLblFile)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxtFile, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtnFile, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jChkInverted)
                .addContainerGap(137, Short.MAX_VALUE))
        );
        jPnlTopLayout.setVerticalGroup(
            jPnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlTopLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPnlTopLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLblFile))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBtnFile, 0, 0, Short.MAX_VALUE)
                            .addComponent(jChkInverted))
                        .addComponent(jTxtFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(41, 41, 41))
        );

        getContentPane().add(jPnlTop, java.awt.BorderLayout.PAGE_START);

        jPnlBottom.setName("jPnlBottom"); // NOI18N
        jPnlBottom.setPreferredSize(new java.awt.Dimension(550, 40));
        jPnlBottom.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jButton1.setAction(actionMap.get("analizeSignal")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("jButton1.toolTipText")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jPnlBottom.add(jButton1);

        jPnlClose.setAction(actionMap.get("closeForm")); // NOI18N
        jPnlClose.setText(resourceMap.getString("jPnlClose.text")); // NOI18N
        jPnlClose.setToolTipText(resourceMap.getString("jPnlClose.toolTipText")); // NOI18N
        jPnlClose.setName("jPnlClose"); // NOI18N
        jPnlBottom.add(jPnlClose);

        getContentPane().add(jPnlBottom, java.awt.BorderLayout.PAGE_END);

        jPnlRigth.setName("jPnlRigth"); // NOI18N
        jPnlRigth.setPreferredSize(new java.awt.Dimension(10, 345));

        javax.swing.GroupLayout jPnlRigthLayout = new javax.swing.GroupLayout(jPnlRigth);
        jPnlRigth.setLayout(jPnlRigthLayout);
        jPnlRigthLayout.setHorizontalGroup(
            jPnlRigthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPnlRigthLayout.setVerticalGroup(
            jPnlRigthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 260, Short.MAX_VALUE)
        );

        getContentPane().add(jPnlRigth, java.awt.BorderLayout.LINE_END);

        jPnlLeft.setName("jPnlLeft"); // NOI18N
        jPnlLeft.setPreferredSize(new java.awt.Dimension(10, 345));

        javax.swing.GroupLayout jPnlLeftLayout = new javax.swing.GroupLayout(jPnlLeft);
        jPnlLeft.setLayout(jPnlLeftLayout);
        jPnlLeftLayout.setHorizontalGroup(
            jPnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPnlLeftLayout.setVerticalGroup(
            jPnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 260, Short.MAX_VALUE)
        );

        getContentPane().add(jPnlLeft, java.awt.BorderLayout.LINE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnFileActionPerformed
        this.controller.plotFile();
    }//GEN-LAST:event_jBtnFileActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnFile;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jChkInverted;
    private javax.swing.JLabel jLblFile;
    private javax.swing.JPanel jPnlBottom;
    private javax.swing.JPanel jPnlCenter;
    private javax.swing.JButton jPnlClose;
    private javax.swing.JPanel jPnlLeft;
    private javax.swing.JPanel jPnlRigth;
    private javax.swing.JPanel jPnlTop;
    private javax.swing.JTextField jTxtFile;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jTxtFile
     */
    public javax.swing.JTextField getjTxtFile() {
        return jTxtFile;
    }

    /**
     * @return the jPnlCenter
     */
    public javax.swing.JPanel getjPnlCenter() {
        return jPnlCenter;
    }

    /**
     * @return the jChkInverted
     */
    public javax.swing.JCheckBox getjChkInverted() {
        return jChkInverted;
    }

    @Action
    public void checkBoxInvertedChange() {
        this.controller.changeInvertedValue();
    }

    @Action
    public void closeForm() {
        this.controller.closeForm();
    }

    @Action
    public void analizeSignal() {
        this.controller.doNewAnalysis();
    }

  
   }
